package com.a.b.c.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Demo1 {
    public static void main(String[] args) {
//        Executors.newCachedThreadPool()   创建一个无边界线程池。
//        ExecutorService executorService = Executors.newCachedThreadPool();
//        executorService.submit(() ->{
//            System.out.println("我是无边界线程池");
//        });
//        executorService.shutdown();
////        Executors.newFixedThreadPool(int nThreads)    创建一个有边界线程池。
//        ExecutorService executorService1 = Executors.newFixedThreadPool(10);
//        executorService1.submit(() -> {
//            System.out.println("我是有边界线程池");
//        });
//        executorService1.shutdown();
//        Executors.newScheduledThreadPool(int corePoolSize)   创建一个可延迟执行的线程池
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);
       /* scheduledExecutorService.submit(() -> {
            System.out.println("我是延迟执行线程池");
        });*/
        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("嘿嘿嘿");
            }
        },3,6,TimeUnit.SECONDS);

//        scheduledExecutorService.shutdown();
////        Executors.newSingleThreadExecutor()   单例线程池，里面只有一天线程，可以用于执行需要有序执行的线程任务
//        ExecutorService executorService2 = Executors.newSingleThreadExecutor();
//        executorService2.submit(() -> {
//            System.out.println("我是单例线程池");
//        });
//        executorService2.shutdown();


    }
}
